package LeetCode.month02.day56;

import java.util.HashMap;
import java.util.Map;

public class No3484 {
}
class Spreadsheet {
    Map<String,Integer> map;

    public Spreadsheet(int rows) {
        map = new HashMap<>();
    }

    public void setCell(String cell, int value) {
        map.put(cell,value);
    }

    public void resetCell(String cell) {
        map.put(cell,0);
    }

    public int getValue(String formula) {
        formula = formula.substring(1);
        String[] strings =  formula.split("\\+");
        int[] arr = new int[2];
        for (int i = 0; i < 2; i++) {
            if(Character.isDigit(strings[i].charAt(0))){
                arr[i] = Integer.parseInt(strings[i]);
            }else{
                arr[i] = map.getOrDefault(strings[i],0);
            }
        }
        return arr[0]+arr[1];
    }
}